package me.ereach;

import java.util.Arrays;

public class NumQueue<T extends Number> {
    private T[] numqueue;
    private int count;

    public NumQueue(int size) {
        numqueue = (T[]) new Number[size];
    }

    public void add(T value) {
        if (count == numqueue.length)
            throw new IllegalArgumentException("队列已满");

        numqueue[count++] = (T) value;
    }

    public T get(int index) {
        return numqueue[index];
    }

    public void remove() {
        if (count > 0)
            numqueue[--count] = null;
        else
            numqueue[0] = null;
    }

    @Override
    public String toString() {
        return Arrays.toString(numqueue);
    }
}
